
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TrainingsApp.Model;
using TrainingsApp.Helper;
using WisDragon.Framework.Data.DataAccess;

namespace TrainingsApp.DAL {
    public class TS_Area_DAL {
        public static TS_Area_Collecion TS_Area_ListByPaging(int pageSize, int pageIndex) {
            TS_Area_Collecion list = new TS_Area_Collecion();
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Area_ListByPaging");
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                List<TS_Area_Entity> pageList = cmd.ExecuteEntityList<TS_Area_Entity>();
                list.TS_Area_List = pageList;
                list.TotalCount = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return list;

        }

        public static List<TS_Area_Entity> TS_Region_ListByAreaId(int provinceId) {

            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Area_ListByProvinceId");
                cmd.SetParameterValue("@ProvinceId", provinceId);

                return cmd.ExecuteEntityList<TS_Area_Entity>();

            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_Area_Entity>(0);

        }


        public static TS_Area_Entity TS_Area_View(System.Int64 Idx) {
            TS_Area_Entity c = default(TS_Area_Entity);
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Area_View");
                cmd.SetParameterValue("@Idx", Idx);
                c = cmd.ExecuteEntity<TS_Area_Entity>();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static TS_Area_Entity TS_Area_Add(TS_Area_Entity entity) {
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Area_Add2");
                cmd.SetParameterValue("@AreaName", entity.AreaName);
                cmd.SetParameterValue("@ProvinceId", entity.ProvinceId);
                cmd.SetParameterValue("@Sort", entity.Sort);
                cmd.SetParameterValue("@Idx", entity.Idx);
                cmd.ExecuteNonQuery();
                entity.Idx = (long)cmd.GetParameterValue("Idx");
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return entity;
        }

        public static bool TS_Area_Update(TS_Area_Entity entity) {
            bool succ = false;
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Area_Update");
                cmd.SetParameterValue("@Idx", entity.Idx);
                cmd.SetParameterValue("@AreaName", entity.AreaName);
                cmd.SetParameterValue("@ProvinceId", entity.ProvinceId);
                cmd.SetParameterValue("@Sort", entity.Sort);
                cmd.ExecuteNonQuery();
                succ = true;
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return succ;
        }

        public static bool TS_Area_Delete(System.Int64 Idx) {
            bool succ = false;
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Area_Delete");
                cmd.SetParameterValue("@Idx", Idx);
                cmd.ExecuteNonQuery();
                succ = true;
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return succ;
        }
    }
}
